package com.example.tool.fragment;

import com.example.tool.R;
import com.example.tool.dao.entity.HealthIndexDomain;
import com.example.tool.mvp.base.IBaseView;
import com.example.tool.util.ValueUtils;

import java.util.List;


/**
 * Created by liangkun on 2018/8/8.
 * 作用:睡眠统计
 */

public class SleepCountFragment extends BaseCountFragment implements IBaseView {
    @Override
    protected void initData() {
        super.initData();
        //图片
        taskImages = new int[]{R.mipmap.iv_sleep_before, R.mipmap.iv_sleep_enough_six, R.mipmap.iv_deep_sleep};
        countTags = getResources().getStringArray(R.array.sleep_count_tag);
        countHints = getResources().getStringArray(R.array.sleep_count_hint);

    }


    @Override
    protected void initView() {
        super.initView();
        tvTabIndex.setText(getString(R.string.sleep_num));
    }


    @Override
    protected void lazyLoad() {

    }

    @Override
    protected void initEvent() {
        barChartView.setOnScaleChangeListener(scale -> {
            tvCountIndex.setText(String.valueOf(indexList.get((int) scale)));
//            tvFinishCount.setText(String.valueOf(taskList.get((int) scale)));
            tvKeepDays.setText(String.valueOf(daysList.get((int) scale)));
//            countRecyclerAdapter.setTaskFinish(taskFinishVos.get((int) scale));
        });
    }

    /**
     * 设置
     *
     * @param indexVos 数据
     */
    @Override
    protected void setBarData(List<HealthIndexDomain> indexVos) {
        indexList.clear();
        taskList.clear();
        daysList.clear();
        barList.clear();
//        taskFinishVos.clear();
        for (HealthIndexDomain domain : indexVos) {
//            int taskTotalFinish = 0;
            //指数
            int score = domain.getSleep();
            indexList.add(score);
            barList.add(score / ValueUtils.BAR_SLEEP_SAORE);
            //累积时间
            int keepTime = domain.getSleepDays();
            daysList.add(keepTime);
            //完成任务个数o
//            String taskFinish = domain.getTaskFinish();
//            HeahthTaskFinishVo taskFinishVo = GsonUtil.fromJson(taskFinish, HeahthTaskFinishVo.class);
//            if (taskFinishVo != null) {
//                //睡眠
//                if (taskFinishVo.getSleep() != null) {
//                    taskTotalFinish = taskFinishVo.getSleep().getCount();
//
//                }
//                taskList.add(taskTotalFinish);
//                taskFinishVos.add(taskFinishVo);
//            }

        }

        barChartView.setData(barList);
        barChartView.setCurrent(29);
        setBarPoint();
//        countRecyclerAdapter = new CountRecyclerAdapter(getContext(), taskImages, countTags, countHints,taskFinishVos.get(29),3);
//        recyclerView.setAdapter(countRecyclerAdapter);
//        dismissLoadingDialog();
    }
}
